package com.rtmanager.ui;

import com.rtmanager.R;
import com.rtmanager.data.Ticket;


import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class ListTicketAdapter extends BaseAdapter {
	
	private Ticket[] listTicket;
	private LayoutInflater mInflater;
	
	
	public ListTicketAdapter(Context context,Ticket[] listTicket ) {
		this.listTicket = listTicket;
		mInflater = LayoutInflater.from(context);
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return listTicket.length-1;
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return listTicket[position];
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return listTicket[position].getId();
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		String TAG = this.getClass().getCanonicalName() + ":getView";
		Log.d(TAG,"position : "+position+" listTicket :"+listTicket.length);
		// TODO Auto-generated method stub
		//rl = (RelativeLayout) convertView.findViewById(R.layout.tpl_ticket);
	
		try {
			
			if ( convertView == null ) {
	
				/*rl = new RelativeLayout(mInflater.getContext());
				TextView tt = new TextView(mInflater.getContext());
				tt.setText("go"+position);
				rl.addView(tt);*/
				convertView= (RelativeLayout) mInflater.inflate(R.layout.ticket_item, null);
				
				
				TextView ticketId = (TextView) convertView.findViewById(R.id.TicketId);
				TextView ticketTitle = (TextView) convertView.findViewById(R.id.TicketTitle);
				TextView TicketDateCreation = (TextView) convertView.findViewById(R.id.TicketDateCreation);
				TextView TicketRequestor = (TextView) convertView.findViewById(R.id.TicketRequestor);
				
				Log.d(TAG,"ticketId :"+ ticketId);
				Log.d(TAG,"ticket : " +listTicket[position].getId().toString() + "|"+listTicket[position].getSubject());
				
				ticketId.setText(listTicket[position].getId().toString());
				ticketTitle.setText(listTicket[position].getSubject());
				TicketDateCreation.setText(listTicket[position].getCreated());
				TicketRequestor.setText(listTicket[position].getRequestors());
	
			}

		}
		catch(Exception e) {
			e.printStackTrace();
		}
		return convertView;
	}
	
}
